package com.careercup.question.id16968662;

public class Solution {
	private static class Node {
		Node left, right;
		int value;
		public Node(int value) {
			this.value = value;
		}
		public int countInsideRange(int min, int max)
		{
			int count = left == null ? 0 : left.countInsideRange(min, max);
			count += right == null ? 0 : right.countInsideRange(min, max);

			if((value > min) && (value < max))
				count++;

			return count;
		}
	}
	/**
	 * @param args
	 */
	 public static void main(String[] args) {
		 Node n1 = new Node(1), n2 = new Node(2);
		 Node n3 = new Node(3), n4 = new Node(4);
		 Node n5 = new Node(5), n6 = new Node(6);
		 Node n7 = new Node(7), n8 = new Node(8);
		 Node n9 = new Node(9), n10 = new Node(10);
		 Node n11 = new Node(11), n12 = new Node(12);
		 Node n13 = new Node(13), n14 = new Node(14);
		 Node n15 = new Node(15);
		 n1.left = n2;
		 n1.right = n3;
		 n2.left = n4;
		 n2.right = n5;
		 n3.left = n6;
		 n3.right = n7;
		 n4.left = n8;
		 n4.right = n9;
		 n5.left = n10;
		 n5.right = n11;
		 n6.left = n12;
		 n6.right = n13;
		 n7.left = n14;
		 n7.right = n15;
		 System.out.println(n1.countInsideRange(4, 9));
	 }
}
